﻿using System;
using Autofac;
using TX.Core;
using TX.Passport.Repositories;

namespace TX.Passport.Repositories
{
    public abstract class IocSetting : IIocSetting
    {  
        public void Register(ContainerBuilder builder, IUnitOfWork unitOfWork)
        {
            RegisterIAdministratorRepository(builder);
            RegisterIDepartmentRepository(builder);
            RegisterIPositionRepository(builder);
            RegisterIPrincipalRepository(builder);
            RegisterIAuthorizationRepository(builder);
            RegisterIOperationRepository(builder);
            RegisterIOperationGroupRepository(builder);
        }
        
        #region AdministratorRepository
        public virtual void RegisterIAdministratorRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetAdministratorRepository()).As<IAdministratorRepository>().PropertiesAutowired();
        }
        public abstract Type GetAdministratorRepository();
        #endregion
        #region DepartmentRepository
        public virtual void RegisterIDepartmentRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetDepartmentRepository()).As<IDepartmentRepository>().PropertiesAutowired();
        }
        public abstract Type GetDepartmentRepository();
        #endregion
        #region PositionRepository
        public virtual void RegisterIPositionRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetPositionRepository()).As<IPositionRepository>().PropertiesAutowired();
        }
        public abstract Type GetPositionRepository();
        #endregion
        #region PrincipalRepository
        public virtual void RegisterIPrincipalRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetPrincipalRepository()).As<IPrincipalRepository>().PropertiesAutowired();
        }
        public abstract Type GetPrincipalRepository();
        #endregion
        #region AuthorizationRepository
        public virtual void RegisterIAuthorizationRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetAuthorizationRepository()).As<IAuthorizationRepository>().PropertiesAutowired();
        }
        public abstract Type GetAuthorizationRepository();
        #endregion
        #region OperationRepository
        public virtual void RegisterIOperationRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetOperationRepository()).As<IOperationRepository>().PropertiesAutowired();
        }
        public abstract Type GetOperationRepository();
        #endregion
        #region OperationGroupRepository
        public virtual void RegisterIOperationGroupRepository(ContainerBuilder builder)
        {
            builder.RegisterType(GetOperationGroupRepository()).As<IOperationGroupRepository>().PropertiesAutowired();
        }
        public abstract Type GetOperationGroupRepository();
        #endregion
    }
}